// pages/login/login.js
import valitate from "wechat-validate"
Page({
  behaviors:[valitate],
  /**
   * 页面的初始数据
   */
  data: {
    showType:true,
    icon:'closed-eye',
    account:'xbsj001',
    password:'123456',
    redirectUrl:''
  },
  rules:{
    account:[
      {required:true,message:"账号不能为空"},
      {min:2,max:16,message:"账号必须是2-16位"}
  ],
    password:[
      {required:true,message:"密码不能为空"},
      {min:6,max:12,message:'密码必须是6-12位'}
  ]
  },
  hIcon(){
    this.setData({showType:!this.data.showType}) 
  },
  async submit(){
    if(!this.validate()) return
    const res = await wx.http.post('/driver/login/account',this.data)
    getApp().setToken('token',res)
    const url = this.data.redirectUrl || '/pages/index/index'
    wx.reLaunch({
      url
    })
  },
  onLoad({redirectUrl}){
    this.setData({redirectUrl})
  }
})